/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */
package poi.Info;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * This class is used to store a LinkedList of Days when the POI is closed
 * 
 * @author Hernani Costa
 * @version 0.1 date: 24/10/2012
 */
public class DaysOff implements Serializable {
	private static final long serialVersionUID = 1L;
	private ArrayList<String> days_off;
	private boolean hasDaysOff;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 */
	public DaysOff() {
		days_off = new ArrayList<String>();
		this.setHasDaysOff(false);
	}

	/**
	 * ------------------------------------------------------------------------
	 * Add the dayOff to the list of DaysOff
	 * ------------------------------------------------------------------------
	 * 
	 * @param dayName
	 */
	public void addDayOff(String dayName) {
		days_off.add(dayName);
		this.setHasDaysOff(true);
	}
	
	public void removeDayOff(String dayName) {
		ArrayList<String> temp = new ArrayList<String>(days_off);
		
		String day="";
		
		for(int i=0 ; i<temp.size(); i++){
			day= temp.get(i);
			if(day.equals(dayName)){
				days_off.remove(i);
				if(days_off.size()==0){
					setHasDaysOff(false);
				}
				break;
			}
		}
	}

	/**
	 * ------------------------------------------------------------------------
	 * Returns the list of DaysOff
	 * ------------------------------------------------------------------------
	 * 
	 * @return a LinkedList<String> with a list of days when the POI is closed
	 */
	public ArrayList<String> getListDaysOff() {
		return days_off;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Returns the list of DaysOff in a String, splitted by commas
	 * ------------------------------------------------------------------------
	 * 
	 * @return a String with all the daysOff, splitted by commas
	 */
	public String getStringDaysOff() {
		String temp = "";
		for (String day : getListDaysOff())
			temp += day + ",";
		if (temp.length() > 1)
			temp = temp.substring(0, temp.length() - 1);
		return temp.trim();
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------
	public boolean hasDaysOff() {
		return hasDaysOff;
	}

	public boolean isDayOff(String dayName){
		boolean flag=false;
		for (String day : days_off){
			//System.out.println(day + " " +dayName);
			if (day.equals(dayName)){
				flag= true;
				break;
			}
		}
		return flag;
	}
	private void setHasDaysOff(boolean hasDaysOff) {
		this.hasDaysOff = hasDaysOff;
	}

}
